/********************************************************************************
 * Project Name		[JavaEE_JDBC]
 * File Name     	[TestCallableStatement.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package jdbc;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import utils.jdbc.JdbcUtils;

/**
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
public class TestCallableStatement {

	private Connection connection;
	private CallableStatement statement;
	private ResultSet resultSet;

	@Before
	public void init() throws Exception {
		connection = JdbcUtils.getInstance().getConnection();
	}

	@Test
	public void testCallableStatement() throws Exception {
		String sql = "{call getSessionID(?, ?)}";
		statement = connection.prepareCall(sql);
		statement.setString(1, "/Catalina/localhost/JavaEE_Web");
		// 注册输出参数
		statement.registerOutParameter(2, java.sql.Types.VARCHAR);
		statement.execute();

		String sessionID = statement.getString(2);
		System.out.println("sessionID = " + sessionID);
	}

	@After
	public void destroy() {
		JdbcUtils.getInstance().close(resultSet, statement, connection);
	}
}
